//
//  BLMeet_Cell_DetailCommon.m
//  Byelone
//
//  Created by 乔小乔 on 2020/12/17.
//

#import "BLMeet_Cell_DetailCommon.h"
@interface BLMeet_Cell_DetailCommon()<UITextViewDelegate>
@end
@implementation BLMeet_Cell_DetailCommon
{
    void(^blockReload)(void);
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.viewBj.layer.cornerRadius = 6;
    [self.viewBj setShadowRadius:16 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 4) opacity:1];
    self.textContent.delegate = self;
    self.textContent.userInteractionEnabled = NO;
    
    self.viewTextBj.layer.cornerRadius = 10;
    self.viewTextBj.layer.masksToBounds = YES;
    self.viewTextBj.layer.borderColor = [UIColor chColorWithHexString:@"#E7E8FF"].CGColor;
    self.viewTextBj.layer.borderWidth = 1;
    self.viewTextBj.hidden = YES;
    
    self.btnEnd.layer.cornerRadius = 9;
    self.btnEnd.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)reloadWithData:(NSString *)strContent{
//    重置爱样式
    self.viewTextBj.hidden = YES;
    self.btnEnd.hidden = YES;
    self.layoutTopSpace.constant = 32;
    self.textContent.userInteractionEnabled = NO;
    if (self.isShouldEdit) {
        self.btnEdit.hidden = NO;
    }else{
        self.btnEdit.hidden = YES;
    }
    self.textContent.text = strContent;
    if (![NSString blIsBlankString:strContent]) {
        self.labelTip.text = @"";
        [self disposeSize];
    }else{
        self.labelTip.text = @"主人比较懒，什么都没有写哦~";
        self.layoutTextHeight.constant = 10;
        self.layoutTipTop.constant = 0;
        if (blockReload) {
            blockReload();
        }
    }
    
}
- (void)disposeSize{
    CGSize constraintSize = CGSizeMake(BL_WINDOW_WIDTH-82, MAXFLOAT);
    CGSize size = [self.textContent sizeThatFits:constraintSize];
    CGFloat height = size.height;
//    输入时最小高度64
    if (height<64&&!self.btnEnd.hidden) {//正在编辑时才需要最小值
        height = 64;
    }
    if (self.layoutTextHeight.constant!=height) {
        self.layoutTextHeight.constant = height;
        if (blockReload) {
            blockReload();
        }
    }
}
-(void)textViewDidChange:(UITextView *)textView{
    if (self.textContent.text.length>0) {
        self.labelTip.text = @"";
    }else{
        self.labelTip.text = @"请输入您的兴趣爱好，最多100字";
        self.layoutTipTop.constant = 8;
    }
    [self disposeSize];
    if (self.editBlock) {
        self.editBlock(textView.text,NO);
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView{
    if (self.editBlock) {
        self.editBlock(textView.text,NO);
    }
}
- (void)blockReloadContent:(void(^)(void))over{
    if (blockReload!=over) {
        blockReload = over;
    }
}
- (IBAction)clickBtn:(UIButton *)sender {
//    101编辑,102保存
    if (sender.tag == 101) {
        self.viewTextBj.hidden = NO;
        self.btnEdit.hidden = YES;
        self.btnEnd.hidden = NO;
        self.layoutTopSpace.constant = 36;
        self.textContent.userInteractionEnabled = YES;
        if (self.textContent.text.length>0) {
            self.labelTip.text = @"";
            
            CGSize constraintSize = CGSizeMake(BL_WINDOW_WIDTH-82, MAXFLOAT);
            CGSize size = [self.textContent sizeThatFits:constraintSize];
            CGFloat height = size.height;
            //    输入时最小高度64
            if (height<64) {
                height = 64;
            }
            if (self.layoutTextHeight.constant!=height) {
                self.layoutTextHeight.constant = height;
            }
        }else{
            self.labelTip.text = @"请输入您的兴趣爱好，最多100字";
            self.layoutTextHeight.constant = 64;
            self.layoutTipTop.constant = 8;
        }
    }else if (sender.tag == 102){
        self.viewTextBj.hidden = YES;
        self.btnEdit.hidden = NO;
        self.btnEnd.hidden = YES;
        self.layoutTopSpace.constant = 32;
        self.textContent.userInteractionEnabled = NO;
        
        if (self.textContent.text.length>0) {
            self.labelTip.text = @"";
//            完成后按照实际内容
            CGSize constraintSize = CGSizeMake(BL_WINDOW_WIDTH-82, MAXFLOAT);
            CGSize size = [self.textContent sizeThatFits:constraintSize];
            CGFloat height = size.height;
            if (self.layoutTextHeight.constant!=height) {
                self.layoutTextHeight.constant = height;
                if (blockReload) {
                    blockReload();
                }
            }
        }else{
            self.labelTip.text = @"主人比较懒，什么都没有写哦~";
            self.layoutTextHeight.constant = 10;
            self.layoutTipTop.constant = 0;
        }
        if (self.editBlock) {
            self.editBlock(self.textContent.text,YES);
        }
    }
    if (blockReload) {
        blockReload();
    }
}


@end
